package web.fabrimind.mwm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import web.fabrimind.common.annotation.Log;
import web.fabrimind.common.core.controller.BaseController;
import web.fabrimind.common.core.domain.AjaxResult;
import web.fabrimind.common.enums.BusinessType;
import web.fabrimind.mwm.domain.MaterialInbound;
import web.fabrimind.mwm.service.IMaterialInboundService;
import web.fabrimind.common.utils.poi.ExcelUtil;
import web.fabrimind.common.core.page.TableDataInfo;

/**
 * 物料入库Controller
 * 
 * @author ruoyi
 * @date 2025-03-26
 */
@RestController
@RequestMapping("/mwm/inbound")
public class MaterialInboundController extends BaseController
{
    @Autowired
    private IMaterialInboundService materialInboundService;

    /**
     * 查询物料入库列表
     */
    @PreAuthorize("@ss.hasPermi('mwm:inbound:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaterialInbound materialInbound)
    {
        startPage();
        List<MaterialInbound> list = materialInboundService.selectMaterialInboundList(materialInbound);
        return getDataTable(list);
    }

    /**
     * 导出物料入库列表
     */
    @PreAuthorize("@ss.hasPermi('mwm:inbound:export')")
    @Log(title = "物料入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialInbound materialInbound)
    {
        List<MaterialInbound> list = materialInboundService.selectMaterialInboundList(materialInbound);
        ExcelUtil<MaterialInbound> util = new ExcelUtil<MaterialInbound>(MaterialInbound.class);
        util.exportExcel(response, list, "物料入库数据");
    }

    /**
     * 获取物料入库详细信息
     */
    @PreAuthorize("@ss.hasPermi('mwm:inbound:query')")
    @GetMapping(value = "/{inboundId}")
    public AjaxResult getInfo(@PathVariable("inboundId") Long inboundId)
    {
        return success(materialInboundService.selectMaterialInboundByInboundId(inboundId));
    }

    /**
     * 新增物料入库
     */
    @PreAuthorize("@ss.hasPermi('mwm:inbound:add')")
    @Log(title = "物料入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialInbound materialInbound)
    {
        return toAjax(materialInboundService.insertMaterialInbound(materialInbound));
    }

    /**
     * 修改物料入库
     */
    @PreAuthorize("@ss.hasPermi('mwm:inbound:edit')")
    @Log(title = "物料入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialInbound materialInbound)
    {
        return toAjax(materialInboundService.updateMaterialInbound(materialInbound));
    }

    /**
     * 删除物料入库
     */
    @PreAuthorize("@ss.hasPermi('mwm:inbound:remove')")
    @Log(title = "物料入库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inboundIds}")
    public AjaxResult remove(@PathVariable Long[] inboundIds)
    {
        return toAjax(materialInboundService.deleteMaterialInboundByInboundIds(inboundIds));
    }
}
